﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GameLogic.Controls;
using GameLogic.Logic;

namespace AirHockey.Phone
{
	public partial class GameContent : UserControl, IGameFeatures
	{
        GameLoop gameLoop;
        public GameContent()
		{
			// Required to initialize variables
			InitializeComponent();

            this.Loaded += new RoutedEventHandler(GameContent_Loaded);
		}

        void GameContent_Loaded(object sender, RoutedEventArgs e)
        {
            GameLoopFinder glf = new GameLoopFinder(LayoutRoot);
            gameLoop = glf.GameLoop;
        }


        public event EventHandler<ScoresChangedEventArgs> ScoresChanged;

        public event EventHandler<LivesChangedEventArgs> LivesChanged;

        public event EventHandler<TimeChangedEventArgs> TimeChanged;

        public event EventHandler<GameOverEventArgs> GameOver;

        public string GameName
        {
            get { return "AirHockey"; }
        }

        public string DeveloperName
        {
            get { return "Dennis Sasse"; }
        }

        public string CompanyName
        {
            get { return "Microsoft Deutschland GmbH"; }
        }

        public string Description
        {
            get { return ""; }
        }

        public TimeSpan GameDuration
        {
            get { return new TimeSpan(); }
        }

        public Uri SettingsPage
        {
            get { return null; }
        }

        public bool IsTimeBased
        {
            get { return false; }
        }

        public bool IsLifeBased
        {
            get { return true; }
        }

        public void Start()
        {
            if (gameLoop != null)
                gameLoop.StartGameLoop();
        }

        public void Stop()
        {
            if (gameLoop != null)
                gameLoop.ResetGameLoop();
        }

        public void Pause()
        {
            if (gameLoop != null)
                gameLoop.PauseGameLoop();
        }

        public void Resume()
        {
            if (gameLoop != null)
                gameLoop.StartGameLoop();
        }

        public void OnScoresChanged(int scores)
        {
            if (ScoresChanged != null)
            {
                ScoresChangedEventArgs args = new ScoresChangedEventArgs();
                args.Scores = scores;

                ScoresChanged(this, args);
            }
        }

        public void OnLivesChanged(int lives)
        {
            if (LivesChanged != null)
            {
                LivesChangedEventArgs args = new LivesChangedEventArgs();
                args.Lives = lives;

                LivesChanged(this, args);
            }
        }
    }
}